<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

JHtml::_('behavior.multiselect');

$user		= JFactory::getUser();
$userId		= $user->get('id');

$doc = JFactory::getDocument();
$doc->addStyleSheet("https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/humanity/jquery-ui.css");
$doc->addStyleSheet(JURI::base()."media/system/css/system.css");
$doc->addStyleSheet(JURI::base()."administrator/templates/bluestork/css/template.css");
$doc->addStyleSheet(JURI::base()."components/com_mariageplanner/css/styles.css");

$doc->addScript("https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js");
$doc->addScriptDeclaration('
		jQuery(document).ready(function() {
			jQuery("button").button();
			
			MP_EditGuest = function(elm) {
				var $tr = jQuery(elm).closest("tr");
				$tr.find("[name=replacer]").remove();
				$tr.find(".readonly").removeClass("readonly").addClass("editable").attr("readonly", false).show();
				
				$tr.find("a.edit").hide();
				$tr.find("a.save").show();
			};

			MP_ReadonlyGuest = function(elm) {
				var $tr = jQuery(elm).closest("tr");

				$tr.find("select.editable, input.editable, textarea.editable").each(function(){ 
					jQuery(this).addClass("readonly").attr("readonly", true); 
					
					if(jQuery(this)[0].tagName.toUpperCase() == "SELECT") {
						jQuery(this).hide();
						jQuery(this).parent()
						.append(
							jQuery("<input name=\'replacer\' readonly=\'readonly\'/>")
							.addClass("readonly")
							.css("width", jQuery(this).width())
							.val(jQuery(this).find("option:selected").text())
						);
					}
				});	
	
				$tr.find("a.save").hide();
				$tr.find("a.edit").show();
			};
	
			MP_AddGuest = function() {
				var $tbody = jQuery("table.adminlist tbody");
				var $tr = $tbody.find("tr").last();
				var $clone = $tr.clone();
				$tbody.append($clone);
				$tr.removeClass("hide");
				$tr.find("[name^=cid]").attr("id", "cbn");
				MP_EditGuest($tr.children().first());
			};		
	
			MP_RemoveGuest = function(elm) {
				var $tr = jQuery(elm).closest("tr");
				var cb = $tr.find("[name^=cid]").attr("id");
				
				if(cb == "cbn")
					$tr.remove();
				else if(confirm("Вы уверены?")) {
					listItemTask(cb, \'guests.delete\');
				}
			};
		
			MP_ShowThrobber = function() {
				jQuery("<div style=\'width: 300px !important; display: table-cell; vertical-align: middle; text-align: center;\'><h2>Сохранение...</h2></div>").dialog({modal: true, resizable: false});
				jQuery(".ui-dialog-titlebar").hide();
			};

			jQuery("table.adminlist tr").each(function(){
				MP_ReadonlyGuest(jQuery(this).children().first()); 
			});		
		});
');
?>
<section class="ui-widget ui-widget-content ui-corner-all" style="padding: 10px;">

<?php if ($userId==0): ?>
<div id="alert_container" class="ui-widget">
	<div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
        <p><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span></p>
        <p>
		<?php echo JText::sprintf( 'COM_MARIAGEPLANNER_GUESTS_LOGIN_WARNING', JRoute::_('index.php?option=com_users&view=login'), JRoute::_('index.php?option=com_users&view=registration')); ?>
		</p>
    </div>
</div>
<?php endif ?>

<form action="<?php echo JRoute::_('index.php?option=com_mariageplanner&view=guests'); ?>" method="post" name="adminForm" id="adminForm">
	<table class="adminlist">
		<thead>
			<tr>
				<th>
					<?php echo JText::_('COM_MARIAGEPLANNER_GUEST_HEADING_NAME'); ?>
				</th>
				<th>
					<?php echo JText::_('COM_MARIAGEPLANNER_GUEST_HEADING_SIDE'); ?>
				</th>
				<th>
					<?php echo JText::_('COM_MARIAGEPLANNER_GUEST_HEADING_STATE'); ?>
				</th>
				<th>
					<?php echo JText::_('COM_MARIAGEPLANNER_GUEST_HEADING_INVITE'); ?>
				</th>
				<!--th>
					<?php echo JText::_('COM_MARIAGEPLANNER_GUEST_HEADING_TABLE'); ?>
				</th-->
				<th width="5%">
				</th>
			</tr>		
		</thead>
		<tfoot>
			<tr>
				<td colspan="5"><span class="jgrid">Пожалуйста, не забудьте нажать значок <span class="state save"></span> для сохранения записи.</span></td>
			</tr>
			<tr>
				<td colspan="5"><?php echo $this->pagination->getListFooter(); ?></td>
			</tr>
		</tfoot>
		<tbody>
	
<?php echo $this->loadTemplate('items'); ?>

		</tbody>
	</table>
	<div>
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="boxchecked" value="0" />
		<?php echo JHtml::_('form.token'); ?>
	</div>

	<div class="toolbar">
		<a href="javascript: void(0);" onclick="MP_AddGuest();"><button class="gradient" type="button">Добавить нового гостя</button></a>
	</div>
</form>

<section>
<?php echo $this->loadTemplate('stat'); ?>
</section>

</section>